package org.my.workflow;

import java.util.List;
import java.util.Collection;

import org.my.workflow.persistence.StepEntity;
import org.my.workflow.persistence.WorkflowEntity;
import org.my.workflow.element.TargetStepElement;

/**
 * @author <a href="mailto:yang_y@sysnet.com.cn">Young Yang</a>
 */
public interface WorkflowPersistence {

    /**
     * 新建Workflow Entity
     * @param workflowId workflow id
     */
    WorkflowEntity newWorkflowEntity(String workflowId);

    /**
     * 更新 workflow entity
     * @param wfEntity workflow entity
     */
    void updateWorkflowEntity(WorkflowEntity wfEntity);

    /**
     * 根据 workflow id 取 workflow entity
     * @param workflowId workflow id
     */
    WorkflowEntity getWorkflowEntity(String workflowId);

    StepEntity getStep(String wfId, String stepEntityId);

    void updateStep(StepEntity stepEntity);

    void finishStep(StepEntity stepEntity);

    /**
     *
     * @param wfContext
     * @param currentStepElementId
     * @param targetStepElements
     */
    Collection<StepEntity> nextSteps(WorkflowContext wfContext, String currentStepElementId, TargetStepElement... targetStepElements);

    Collection<StepEntity> getCurrentSteps(String wfId);

    List<StepEntity> getHistorySteps(String wfId);

}
